<?php

Class adminController Extends baseController {

    public function index() 
    {
            $this->registry->template->showAdmin('admin_index');
    }
    
    public function list_account()
    {
        $accountDAO = CreateObject("Model_DAO_Account");
          $page = 1;
        if(isset($_REQUEST["p"]))
        {
            $page = intval($_REQUEST["p"]);
        }
        $row_total = getRow("select * from ".table_prefix("room"));
        $page_size = 10;
        $pagegroup_size =5;
        $url="index.php?rt=admin/list_room";
        
        $accounts = $accountDAO->lists($page*$page_size-$page_size,$page_size);
        $this->registry->template->page = $page;
        $this->registry->template->row_total = $row_total;
        $this->registry->template->page_size = $page_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->url = $url;
        $this->registry->template->accounts = $accounts;
        $this->registry->template->showAdmin('list_account');
    }
    
    public function create_account()
    {
        $this->registry->template->showAdmin('create_account');
    }
    
    public function  post_create_account()
    {
        if(isset($_POST["submit"]))
        {
            $firstname = $_POST["firstname"];
            $lastname = $_POST["lastname"];
            $birthday = $_POST["birthday"];
            $address = $_POST["address"];
            $phone = $_POST["phone"];
            $avartar = $_POST["avartar"];
            $email = $_POST["email"];
            $username = $_POST["username"];
            $password = $_POST["password"];
            $role = $_POST["role"];
            $status = $_POST["status"];
            
            $account = CreateObject("Model_Entity_Account");
            $account->init($firstname,$lastname,$birthday,$address,$phone,$avartar,$email,$username,$password,$role,$status);
            if($account->validation())
            {
                $accountDAO = CreateObject("Model_DAO_Account");
                if($accountDAO->create($account))
                {
                     header("Location: index.php?rt=admin/list_account");
                }
                else
                {
                    $_SESSION["create_account"] = $account;
                    $_SESSION["error_create_account"] = 1;
                     header("Location: index.php?rt=admin/create_account");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_account");
        }
    }
    
    public function  post_edit_account()
    {
        if(isset($_POST["submit"]))
        {
            $id = $_POST["id"];
            $firstname = $_POST["firstname"];
            $lastname = $_POST["lastname"];
            $birthday = $_POST["birthday"];
            $address = $_POST["address"];
            $phone = $_POST["phone"];
            $avartar = $_POST["avartar"];
            $email = $_POST["email"];
            $username = $_POST["username"];
            $password = $_POST["password"];
            $role = $_POST["role"];
            $status = $_POST["status"];
            
            $account = CreateObject("Model_Entity_Account");
            $account->init($id,$firstname,$lastname,$birthday,$address,$phone,$avartar,$email,$username,$password,$role,$status);
            if($account->validation())
            {
                $accountDAO = CreateObject("Model_DAO_Account");
                if($accountDAO->update($account))
                {
                     header("Location: index.php?rt=admin/list_account");
                }
                else
                {
                    $_SESSION["create_account"] = $account;
                    $_SESSION["error_create_account"] = 1;
                     header("Location: index.php?rt=admin/edit_account");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_account");
        }
    }
    
    public function edit_account()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $accountDAO = CreateObject("Model_DAO_Account");
            $account = $accountDAO->get($id);
            $this->registry->template->account = $account;
            $this->registry->template->showAdmin('edit_account');
        }
        else
        {
            header("Location: index.php?rt=admin/list_account");
        }
    }
    
    public function details_account()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $accountDAO = CreateObject("Model_DAO_Account");
            $account = $accountDAO->get($id);
            $this->registry->template->account = $account;
            $this->registry->template->showAdmin('details_account');
        }
        else
        {
            header("Location: index.php?rt=admin/list_account");
        }
    }
    
    public function delete_account()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $accountDAO = CreateObject("Model_DAO_Account");
            $status = $accountDAO->delete($id);
            header("Location: index.php?rt=admin/list_account");
        }
        else
        {
            header("Location: index.php?rt=admin/list_account");
        }
    }
    
    public function list_role()
    {
        $start = 0;
        $length = 10;
        $roleDAO = CreateObject("Model_DAO_Role");
        $roles = $roleDAO->lists($start,$length);
        $this->registry->template->roles = $roles;
        $this->registry->template->showAdmin('list_role');
    }
    
    public function create_role()
    {
        $this->registry->template->showAdmin('create_role');
    }
    
    public function post_create_role()
    {
        if(isset($_POST["submit"]))
        {
            $name = $_POST["name"];
            $status = $_POST["status"];
            $id = 0;
            $role = CreateObject("Model_Entity_Role");
            $role->init($id,$name,$status);
            $role->updated = date("now");
            if($role->validation())
            {
                $roleDAO = CreateObject("Model_DAO_Role");
                if($roleDAO->create($role))
                {
                     header("Location: index.php?rt=admin/list_role");
                }
                else
                {
                    $_SESSION["create_role"] = $role;
                    $_SESSION["error_create_role"] = 1;
                     header("Location: index.php?rt=admin/create_role");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_role");
        }
    }
    
    public function  post_edit_role()
    {
        if(isset($_POST["submit"]))
        {
            $id = $_POST["id"];
            $name = $_POST["name"];
            $status = $_POST["status"];
            
            $role = CreateObject("Model_Entity_Role");
            $role->init($name,$status);
            if($role->validation())
            {
                $roleDAO = CreateObject("Model_DAO_Role");
                if($roleDAO->update($role))
                {
                     header("Location: index.php?rt=admin/list_role");
                }
                else
                {
                    $_SESSION["edit_role"] = $role;
                    $_SESSION["error_edit_role"] = 1;
                     header("Location: index.php?rt=admin/edit_role");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_role");
        }
    }
    
    public function edit_role()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $roleDAO = CreateObject("Model_DAO_Role");
            $role = $roleDAO->get($id);
            $this->registry->template->role = $role;
            $this->registry->template->showAdmin('edit_role');
        }
        else
        {
            header("Location: index.php?rt=admin/list_role");
        }
    }
    
    
    public function details_role()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $roleDAO = CreateObject("Model_DAO_Role");
            $role = $roleDAO->get($id);

            $this->registry->template->role = $role;
            $this->registry->template->showAdmin('details_role');
        }
        else
        {
            header("Location: index.php?rt=admin/list_role");
        }
    }
    
    public function delete_role()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $roleDAO = CreateObject("Model_DAO_Role");
            $status = $roleDAO->delete($id);
            header("Location: index.php?rt=admin/list_role");
        }
        else
        {
            header("Location: index.php?rt=admin/list_role");
        }    
    }
    
    public function list_duong()
    {
        $duongDAO = CreateObject("Model_DAO_Duong");
        $page = 1;
        if(isset($_REQUEST["p"]))
        {
            $page = intval($_REQUEST["p"]);
        }
        $row_total = getRow("select * from ".table_prefix("duong"));
        $page_size = 5;
        $pagegroup_size =5;
        $url="index.php?rt=admin/list_duong";
        $duongs = $duongDAO->lists($page*$page_size-$page_size,$page_size);
        $this->registry->template->page = $page;
        $this->registry->template->row_total = $row_total;
        $this->registry->template->page_size = $page_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->url = $url;
        
        $this->registry->template->duongs = $duongs;
        $this->registry->template->showAdmin('list_duong');
    }
    
    
    public function create_duong()
    {
        $this->registry->template->showAdmin('create_duong');
    }
    
    public function  post_create_duong()
    {
        if(isset($_POST["submit"]))
        {
            $name = $_POST["name"];
            $status = $_POST["status"];
            $order = 0;
            $id = 0;
            $duong = CreateObject("Model_Entity_Duong");
            $duong->init($id,$name,$order,$status);
            $duong->updated = date("now");
            if($duong->validation())
            {
                $duongDAO = CreateObject("Model_DAO_Duong");
                
                if($duongDAO->create($duong))
                {
                     header("Location: index.php?rt=admin/list_duong");
                }
                else
                {
                    $_SESSION["create_duong"] = $duong;
                    $_SESSION["error_create_duong"] = 1;
                     header("Location: index.php?rt=admin/create_duong");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_duong");
        }
    }
    
    public function  post_edit_duong()
    {
        if(isset($_POST["submit"]))
        {
            $id = $_POST["id"];
            $name = $_POST["idroom"];
            $order = $_POST["order"];
            $status = $_POST["name"];
            
            $duong = CreateObject("Model_Entity_Duong");
            $duong->init($id,$name,$order,$status);
            if($duong->validation())
            {
                $duongDAO = CreateObject("Model_DAO_Comment");
                if($duongDAO->update($duong))
                {
                     header("Location: index.php?rt=admin/list_duong");
                }
                else
                {
                    $_SESSION["create_duong"] = $duong;
                    $_SESSION["error_create_duong"] = 1;
                     header("Location: index.php?rt=admin/edit_duong");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_duong");
        }
    }
    
    public function edit_duong()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $duongDAO = CreateObject("Model_DAO_Duong");
            $duong = $duongDAO->get($id);
            $this->registry->template->duong = $duong;
             $this->registry->template->showAdmin('edit_duong');
        }
        else
        {
            header("Location: index.php?rt=admin/list_duong");
        }
    }
    
    public function details_duong()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $duongDAO = CreateObject("Model_DAO_Duong");
            $duong = $duongDAO->get($id);
            $this->registry->template->duong = $duong;
            $this->registry->template->showAdmin('details_duong');
        }
        else
        {
            header("Location: index.php?rt=admin/list_duong");
        }
    }
    
    public function delete_duong()
    {
        debug($_REQUEST,1);
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $duongDAO = CreateObject("Model_DAO_Duong");
            $status = $duongDAO->delete($id);
            header("Location: index.php?rt=admin/list_duong");
        }
        else
        {
            header("Location: index.php?rt=admin/list_duong");
        }
    }
    
    public function delete_truong()
    {
        debug($_REQUEST,1);
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $duongDAO = CreateObject("Model_DAO_Truong");
            $status = $duongDAO->delete($id);
            header("Location: index.php?rt=admin/list_truong");
        }
        else
        {
            header("Location: index.php?rt=admin/list_truong");
        }
    }
    
    public function list_phuong()
    {
        $phuongDAO = CreateObject("Model_DAO_Phuong");
        $page = 1;
        if(isset($_REQUEST["p"]))
        {
            $page = intval($_REQUEST["p"]);
        }
        $row_total = getRow("select * from ".table_prefix("phuong"));
        $page_size = 5;
        $pagegroup_size =5;
        
        $url="index.php?rt=admin/list_phuong";
        $this->registry->template->page = $page;
        $this->registry->template->row_total = $row_total;
        $this->registry->template->page_size = $page_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->url = $url;
        $phuongs = $phuongDAO->lists($page*$page_size-$page_size,$page_size);
        $this->registry->template->phuongs = $phuongs;
        $this->registry->template->showAdmin('list_phuong');
    }
    
    public function create_phuong()
    {
        $this->registry->template->showAdmin('create_phuong');
    }
    
    public function  post_create_phuong()
    {
        if(isset($_POST["submit"]))
        {
            $name = $_POST["name"];
            $status = $_POST["status"];
            $order = 0;
            $id = 0;            
            $phuong = CreateObject("Model_Entity_Phuong");
            $phuong->init($id,$name,$order,$status);
            $phuong->updated = date("now");
            if($phuong->validation())
            {
                $phuongDAO = CreateObject("Model_DAO_Phuong");
                if($phuongDAO->create($phuong))
                {
                     header("Location: index.php?rt=admin/list_phuong");
                }
                else
                {
                    $_SESSION["create_phuong"] = $phuong;
                    $_SESSION["error_create_phuong"] = 1;
                     header("Location: index.php?rt=admin/create_phuong");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_phuong");
        }
    }
    
    public function  post_edit_phuong()
    {
        if(isset($_POST["submit"]))
        {
            $id = $_POST["id"];
            $name = $_POST["name"];
            $order = $_POST["order"];
            $status = $_POST["status"];
            
            $phuong = CreateObject("Model_Entity_Phuong");
            $phuong->init($id,$name,$order,$status);
            if($phuong->validation())
            {
                $phuongDAO = CreateObject("Model_DAO_Phuong");
                if($phuongDAO->update($phuong))
                {
                     header("Location: index.php?rt=admin/list_phuong");
                }
                else
                {
                    $_SESSION["edit_phuong"] = $phuong;
                    $_SESSION["error_edit_phuong"] = 1;
                     header("Location: index.php?rt=admin/edit_phuong");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_phuong");
        }
    }
    
    public function edit_phuong()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $phuongDAO = CreateObject("Model_DAO_Phuong");
            $phuong = $phuongDAO->get($id);
            $this->registry->template->phuong = $phuong;
            $this->registry->template->showAdmin('edit_phuong');
        }
        else
        {
            header("Location: index.php?rt=admin/list_phuong");
        }
    }
    
    public function details_phuong()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $phuongDAO = CreateObject("Model_DAO_Phuong");
            $phuong = $phuongDAO->get($id);
            $this->registry->template->phuong = $phuong;
            $this->registry->template->showAdmin('details_phuong');
        }
        else
        {
            header("Location: index.php?rt=admin/list_phuong");
        }
    }
    
    public function delete_phuong()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $phuongDAO = CreateObject("Model_DAO_Phuong");
            $status = $phuongDAO->delete($id);
            header("Location: index.php?rt=admin/list_phuong");
        }
        else
        {
            header("Location: index.php?rt=admin/list_phuong");
        }
    }
    
    public function list_truong()
    {
        $truongDAO = CreateObject("Model_DAO_Truong");
        $page = 1;
        if(isset($_REQUEST["p"]))
        {
            $page = intval($_REQUEST["p"]);
        }
        $row_total = getRow("select * from ".table_prefix("truong"));
        $page_size = 5;
        $pagegroup_size =5;
        $url="index.php?rt=admin/list_truong";
        
        $truongs = $truongDAO->lists($page*$page_size-$page_size,$page_size);
         $this->registry->template->page = $page;
        $this->registry->template->row_total = $row_total;
        $this->registry->template->page_size = $page_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->url = $url;
        $this->registry->template->truongs = $truongs;
        $this->registry->template->showAdmin('list_truong');
    }
    
    public function create_truong()
    {
        $this->registry->template->showAdmin('create_truong');
    }
    
    public function  post_create_truong()
    {
        if(isset($_POST["submit"]))
        {
            $name = $_POST["name"];
            $status = $_POST["status"];
            $order = 0;
            $id = 0;           
            
            $truong = CreateObject("Model_Entity_Truong");
            $truong->init($id,$name,$order,$status);
            $truong->updated = date("now");
            if($truong->validation())
            {
                $truongDAO = CreateObject("Model_DAO_Truong");
                if($truongDAO->create($truong))
                {
                     header("Location: index.php?rt=admin/list_truong");
                }
                else
                {
                    $_SESSION["create_truong"] = $truong;
                    $_SESSION["error_create_truong"] = 1;
                     header("Location: index.php?rt=admin/create_truong");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_truong");
        }
    }
    
     public function  post_edit_truong()
    {
        if(isset($_POST["submit"]))
        {
            $id = $_POST["id"];
            $name = $_POST["name"];
            $order = $_POST["order"];
            $status = $_POST["status"];
            
            $truong = CreateObject("Model_Entity_Truong");
            $truong->init($id,$name,$order,$status);
            if($truong->validation())
            {
                $truongDAO = CreateObject("Model_DAO_Truong");
                if($truongDAO->update($truong))
                {
                     header("Location: index.php?rt=admin/list_truong");
                }
                else
                {
                    $_SESSION["edit_truong"] = $truong;
                    $_SESSION["error_edit_truong"] = 1;
                     header("Location: index.php?rt=admin/edit_truong");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_truong");
        }
    }
    
    public function edit_truong()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $truongDAO = CreateObject("Model_DAO_Truong");
            $truong = $truongDAO->get($id);
            $this->registry->template->truong = $truong;
            $this->registry->template->showAdmin('edit_truong');
        }
        else
        {
            header("Location: index.php?rt=admin/list_truong");
        }
    }
    
    public function details_truong()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $truongDAO = CreateObject("Model_DAO_Truong");
            $truong = $truongDAO->get($id);
            $this->registry->template->truong = $truong;
            $this->registry->template->showAdmin('details_truong');
        }
        else
        {
            header("Location: index.php?rt=admin/list_truong");
        }
    }
    
    public function list_section()
    {
        $sectionDAO = CreateObject("Model_DAO_Section");
        $page = 1;
        if(isset($_REQUEST["p"]))
        {
            $page = intval($_REQUEST["p"]);
        }
        $row_total = getRow("select * from ".table_prefix("section"));
        $page_size = 5;
        $pagegroup_size =5;
        $url="index.php?rt=admin/list_section";
        $sections = $sectionDAO->lists($page*$page_size-$page_size,$page_size);
         $this->registry->template->page = $page;
        $this->registry->template->row_total = $row_total;
        $this->registry->template->page_size = $page_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->url = $url;
        $this->registry->template->sections = $sections;
        $this->registry->template->showAdmin('list_section');
    }
    
    public function list_room()
    {
        $roomDAO = CreateObject("Model_DAO_Room");
        $order = 1;
        $page = 1;
        if(isset($_REQUEST["p"]))
        {
            $page = intval($_REQUEST["p"]);
        }
        $row_total = getRow("select * from ".table_prefix("room"));
        $page_size = 10;
        $pagegroup_size =5;
        $url="index.php?rt=admin/list_room";
        
        $rooms = $roomDAO->lists($order,$page*$page_size-$page_size,$page_size);
        $this->registry->template->page = $page;
        $this->registry->template->row_total = $row_total;
        $this->registry->template->page_size = $page_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->url = $url;
        $this->registry->template->rooms = $rooms;
        $this->registry->template->showAdmin('list_room');
    }
    
    public function create_room()
    {
        $duongDAO = CreateObject("Model_DAO_Duong");
        $phuongDAO = CreateObject("Model_DAO_Phuong");
        $duongs = $duongDAO->lists();
        $phuongs = $phuongDAO->lists();
        $this->registry->template->duongs = $duongs;
        $this->registry->template->phuongs = $phuongs;
        $this->registry->template->showAdmin('create_room');
    }
    
    public function edit_room()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $roomDAO = CreateObject("Model_DAO_Room");
           
            $room = $roomDAO->get($id);
            $this->registry->template->room = $room;
  
            $this->registry->template->showAdmin('edit_room');
        }
        else
        {
            header("Location: index.php?rt=admin/list_room");
        }
    }
    
    public function details_room()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $roomDAO = CreateObject("Model_DAO_Room");
            $room = $roomDAO->get($id);
            $this->registry->template->room = $room;
            $this->registry->template->showAdmin('details_room');
        }
        else
        {
            header("Location: index.php?rt=admin/list_room");
        }
    }
    
    public function delete_room()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $roomDAO = CreateObject("Model_DAO_Room");
            $status = $roomDAO->delete($id);
            header("Location: index.php?rt=admin/list_room");
        }
        else
        {
            header("Location: index.php?rt=admin/list_room");
        }
    }
    
    public function  post_create_room()
    {
        if(isset($_POST["submit"]))
        {
            $room = CreateObject("Model_Entity_Room");
            $room->title = $_POST["title"];
            $room->shortdescription = $_POST["shortdescription"];
            $room->description = $_POST["description"];
            $room->new = $_POST["new"];
            $room->is_phong_khep_kin = $_POST["is_phong_khep_kin"];
            $room->sonha = $_POST["sonha"];
            $room->kiet = $_POST["kiet"];
            $room->tongsophong = $_POST["tongsophong"];
            $room->sophongcontrong = $_POST["sophongcontrong"];
            $room->tenchunha = $_POST["tenchunha"];
            $room->address = $_POST["address"];
            $room->idduong = $_POST["idduong"];
            $room->idphuong = $_POST["idphuong"];
            $room->dt_nha = $_POST["dt_nha"];
            $room->dt_didong = $_POST["dt_didong"];
            $room->email = $_POST["email"];
            $room->gioi_tinh_thue = $_POST["gioi_tinh_thue"];
            $room->gia_phong_max = $_POST["gia_phong_max"];
            $room->gia_phong_min = $_POST["gia_phong_min"];
            $room->giadien = $_POST["giadien"];
            $room->gia_nuoc = $_POST["gia_nuoc"];
            $room->gan_cho = $_POST["gan_cho"];
            $room->internet = $_POST["internet"];
            $room->isGoogleMap = $_POST["isGoogleMap"];
            $room->longitude = $_POST["longitude"];
            $room->glatitude = $_POST["latitude"];
            $room->contentGoogleMap = $_POST["contentGoogleMap"];
            $room->titleGoogleMap = $_POST["titleGoogleMap"];
            $room->stick = $_POST["stick"];
            $room->status = $_POST["status"];
            $room->view = 0;
            $room->create_by = 1;
            $room->create_date = date("now");
            $room->update_by = 1;
            $room->updated = date("now");
            $room->order = 0;
            $room->id = 0;
            $room->updated = date("now");
            if($room->validation())
            {
                $roomDAO = CreateObject("Model_DAO_Room");
                
                debug($roomDAO->create($room));
                exit();
                if($roomDAO->create($room))
                {
                     header("Location: index.php?rt=admin/list_room");
                }
                else
                {
                    $_SESSION["create_room"] = $room;
                    $_SESSION["error_create_room"] = 1;
                     header("Location: index.php?rt=admin/create_room");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_room");
        }
    }
    
    public function list_comment()
    {
        $commentDAO = CreateObject("Model_DAO_Comment");
        $page = 1;
        if(isset($_REQUEST["p"]))
        {
            $page = intval($_REQUEST["p"]);
        }
        $row_total = getRow("select * from ".table_prefix("comment"));
        $page_size = 10;
        $pagegroup_size =5;
        $url="index.php?rt=admin/list_comment";
   
        $comments = $commentDAO->lists($page*$page_size-$page_size,$page_size);
         $this->registry->template->page = $page;
        $this->registry->template->row_total = $row_total;
        $this->registry->template->page_size = $page_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->pagegroup_size = $pagegroup_size;
        $this->registry->template->url = $url;
        
        $this->registry->template->comments = $comments;
        $this->registry->template->showAdmin('list_comment');
    }
    
    public function create_comment()
    {
        $this->registry->template->showAdmin('create_comment');
    }
    
    public function  post_create_comment()
    {
        if(isset($_POST["submit"]))
        {
            $idroom = $_POST["idroom"];
            $title = $_POST["title"];
            $content = $_POST["content"];
            $name = $_POST["name"];
            $created_by = $_POST["created_by"];
            $status = $_POST["status"];
            
            $comment = CreateObject("Model_Entity_Comment");
            $comment->init($idroom,$title,$content,$name,$created_by,$status);
            if($comment->validation())
            {
                $commentDAO = CreateObject("Model_DAO_Comment");
                if($commentDAO->create($comment))
                {
                     header("Location: index.php?rt=admin/list_comment");
                }
                else
                {
                    $_SESSION["create_comment"] = $comment;
                    $_SESSION["error_create_comment"] = 1;
                     header("Location: index.php?rt=admin/create_comment");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_comment");
        }
    }
    
    public function  post_edit_comment()
    {
        if(isset($_POST["submit"]))
        {
            $id = $_POST["id"];
            $idroom = $_POST["idroom"];
            $title = $_POST["title"];
            $content = $_POST["content"];
            $name = $_POST["name"];
            $created_by = $_POST["created_by"];
            $status = $_POST["status"];
            
            $comment = CreateObject("Model_Entity_Comment");
            $comment->init($id,$idroom,$title,$content,$name,$created_by,$status);
            if($comment->validation())
            {
                $commentDAO = CreateObject("Model_DAO_Comment");
                if($commentDAO->update($comment))
                {
                     header("Location: index.php?rt=admin/list_comment");
                }
                else
                {
                    $_SESSION["create_comment"] = $comment;
                    $_SESSION["error_create_comment"] = 1;
                     header("Location: index.php?rt=admin/edit_comment");
                }
            }
        }
        else
        {
            header("Location: index.php?rt=admin/list_comment");
        }
    }
    
    public function edit_comment()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $commentDAO = CreateObject("Model_DAO_Comment");
            $comment = $commentDAO->get($id);
            $this->registry->template->room = $comment;
            $this->registry->template->showAdmin('edit_comment');
        }
        else
        {
            header("Location: index.php?rt=admin/list_comment");
        }
    }
    
    public function details_comment()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $commentDAO = CreateObject("Model_DAO_Comment");
            $comment = $commentDAO->get($id);
            $this->registry->template->comment = $comment;
            $this->registry->template->showAdmin('details_comment');
        }
        else
        {
            header("Location: index.php?rt=admin/list_comment");
        }
    }
    
    public function delete_comment()
    {
        if(isset($_REQUEST["id"]) && is_int(intval($_REQUEST["id"])) )
        {
            $id = $_REQUEST["id"];
            $commentDAO = CreateObject("Model_DAO_Comment");
            $status = $commentDAO->delete($id);
            header("Location: index.php?rt=admin/list_comment");
        }
        else
        {
            header("Location: index.php?rt=admin/list_comment");
        }
    }
}
?>
